package com.vagavaga.bizworld.jpatx;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import javax.persistence.EntityManager;
import javax.persistence.FlushModeType;

abstract class EntityManagerInterceptor implements InvocationHandler {
    protected static final Method SET_FLUSH_MODE;
    protected static final Method JOIN_TRANSACTION;
    protected static final Method GET_TRANSACTION;
    protected static final Method CLEAR;
    protected static final Method CLOSE;
    protected static final Method FLUSH;
    protected static final Method GET_DELEGATE;

    static {
        try {
            SET_FLUSH_MODE = EntityManager.class.getMethod("setFlushMode", FlushModeType.class); //$NON-NLS-1$
            JOIN_TRANSACTION = EntityManager.class.getMethod("joinTransaction", (Class[]) null); //$NON-NLS-1$
            GET_TRANSACTION = EntityManager.class.getMethod("getTransaction", (Class[]) null); //$NON-NLS-1$
            CLEAR = EntityManager.class.getMethod("clear", (Class[]) null); //$NON-NLS-1$
            CLOSE = EntityManager.class.getMethod("close", (Class[]) null); //$NON-NLS-1$
            FLUSH = EntityManager.class.getMethod("flush", (Class[]) null); //$NON-NLS-1$
            GET_DELEGATE = EntityManager.class.getMethod("getDelegate", (Class[]) null); //$NON-NLS-1$
        } catch (Exception e) {
            throw new RuntimeException("Unable to initialize", e); 
        }
    }
}
